#include<iosteram>
#include<assert.h>
using namespace std;

namespace  My
{
   template<typename T>
     class Stack()
     {
       public:
         Stack(const size_t capacity=0)
         {
           if(capacity>0)
           {
             _a=new T[capacity];
             _capacity=capacity;
           }

         }
         Stack(const Stack &s1)
         {
            T*tmp=new T[s1._capacity];
            if(_a)
            {
              memst(tmp,_a,sizeof(T)*s1._capacity);
            }
            _capacity=s1._capacity;
            _top=s1._top;
            _a=tmp;
         }

         ~Stack()
         {
           delete[] _a;
          _a=nullptr;
          _top=_capacity=0;
         }

         void Push(const T &x)
         {
           if(_top==_capacity)
           {
              size_t  newcapacity=_capacity==0?4:_capacity*2;
              T*tmp = new T[newcapacity];
              if(_a)
              {
                memcpy(tmp,_a,sizeof(T)*_capacity);
                delete [] _a;
              }
              _a=tmp;
              _capacity=newcapacity;
           }
           _a[_top++]=x;
         }

         bool Empty()
         {
               return _top==0;
         }

         void Pop()
         {
           assert(_top>0);
           _top--;
         }

        const  T& Top()
         {
           assert(_top>0);
           return _a[top-1];
         }


       private:
       
         T* _a=nullptr;
         size_t  _top=0;
         size_t  _capacity=0;
       
     }

}
